import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.0
//import QtQuick.Window 2.0

Rectangle {
    property int getting_width: 800
    property int getting_height: 480
    property string bg_color: "white"
    property string tf_text_color: "#6d300b"
    property string bg_sell: "#aaaaaa"
    property string brd_sell: "white"
    property string text_sell: "#303030"
    width: getting_width
    height: getting_height
    Component.onCompleted:
    {
        A_model.refresh()
    }

    Rectangle
    {
        id:background
        width: getting_width
        height:getting_height
        anchors.centerIn: parent
        color:bg_color
    }
    Component {
        id: delegate
        //"VALUES (:item,:bid,:buyout,:quantity,:timeLeft,:rand,:seed)");
        Rectangle {
            property int _sell_height:25
            width: getting_width-10
            height:_sell_height
            color:bg_sell
            border.color:brd_sell
            anchors.horizontalCenter:  parent.horizontalCenter
            Row
            {
                Rectangle
                {
                    id: sub_delegate_1
                    width: 20
                    height: 20
                    x:5
                    color: bg_sell
                    border.color:brd_sell
                    radius: 5
                    anchors.verticalCenter: parent.verticalCenter
                    Image
                    {
                        id: itemIcon18px
                        source: "http://media.blizzard.com/wow/icons/18/"+icon+".jpg"
                        anchors.horizontalCenter: parent.horizontalCenter
                        anchors.verticalCenter: parent.verticalCenter
                    }
                }
                Text {
                    id: sub_delegate_01
                    width: 35
                    anchors.leftMargin: 5
                    text: id
                    anchors.verticalCenter: parent.verticalCenter
                    color: text_sell
                }
                Text {
                    id: sub_delegate_2
                    anchors.leftMargin: 5
                    width: 135
                    text: name
                    anchors.verticalCenter: parent.verticalCenter
                    color: text_sell
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                }
                /*  Text {
                id: sub_delegate_3
                anchors.leftMargin: 5
                width: 250
                text: bid
                anchors.verticalCenter: parent.verticalCenter
                color: text_sell
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
            }*/
                Text {
                    id: sub_delegate_4
                    anchors.leftMargin: 5
                    width: 250
                    text: stringExecut (buyout,"*").split("*")[0]+stringExecut (buyout,"*").split("*")[2]
                    anchors.verticalCenter: parent.verticalCenter
                    color: text_sell
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                }
                Text {
                    id: sub_delegate_5
                    anchors.leftMargin: 5
                    width: 50
                    text: quantity
                    anchors.verticalCenter: parent.verticalCenter
                    color: text_sell
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter

                }
                Text {
                    id: sub_delegate_6
                    anchors.leftMargin: 5
                    width: 100
                    text: timeLeft
                    font.pointSize: 5
                    anchors.verticalCenter: parent.verticalCenter
                    color: text_sell
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                }
                /*  Text {
                id: sub_delegate_7
                anchors.leftMargin: 5
                width: 50
                text: rand
                anchors.verticalCenter: parent.verticalCenter
                color: text_sell
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
            }
            Text {
                id: sub_delegate_8
                anchors.leftMargin: 5
                width: 50
                text: seed
                anchors.verticalCenter: parent.verticalCenter
                color: text_sell
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
            }*/

            }
            MouseArea
            {
                anchors.fill: parent
                hoverEnabled: true
                onClicked:
                {
                    grid_view1.currentIndex = index
                    currentIt._T1 = index
                    console.log(index)
                    shade.visible = true
                    shade.enabled = true
                    currentIt.width = 200
                    currentIt.height = 60
                    grid_view1.enabled = false

                }
            }
        }
    }
    ListView {
        id: grid_view1
        width: getting_width
        height: getting_height
        anchors.fill: parent
        anchors.topMargin: 5
        anchors.bottomMargin: 5
        spacing: -1
        model: A_model
        delegate: delegate
    }

    Item
    {
        id: shade
        anchors.fill: parent
        visible: false
        enabled: false
        Rectangle
        {
            anchors.fill: parent
            color:"grey"
            opacity: 0.555
        }
        MouseArea
        {
            anchors.fill:parent
            onClicked:
            {
                shade.visible = false
                shade.enabled = false
                currentIt.width = 0
                currentIt.height = 0
                grid_view1.enabled = true
            }
        }

    }
    Item
    {
        id: currentIt
        property string _T1: ""
        anchors.centerIn:  parent
        width:0
        height: 0
        visible:  (currentIt.width>0)?true:false
        enabled:  (currentIt.width>0)?true:false
        Rectangle
        {
            id: _R1
            anchors.fill:  parent
            color: bg_sell
            border.color:brd_sell
            border.width: 2
            Text
            {
                color: text_sell
                anchors.fill:  parent
                text: currentIt._T1
                font.pointSize: 20
                visible:  (currentIt.width>100)?true:false
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
            }
        }
        MouseArea
        {
            anchors.fill:parent
            onClicked:
            {

            }
        }
        Behavior on width
        {
            NumberAnimation { easing.type: Easing.InOutBack; duration: 500 }
        }
        Behavior on height
        {
            NumberAnimation { easing.type: Easing.InOutBack; duration: 500 }
        }
    }
    Button
    {
        id:button_A
        property string gr_color_one:"black"
        property string gr_color_two:"#303030"
        style: ButtonStyle
        {  background: Rectangle {
            implicitWidth: 100
            implicitHeight: 25
            border.width: control.activeFocus ? 2 : 1
            border.color: "black"
            radius: 1
            color: bg_sell
        }
    }
    visible: false
    anchors.bottom: parent.bottom
    anchors.left: parent.left
    width: parent.width/2-5
}
Button
{
    id:button_B
    property string gr_color_one:"black"
    property string gr_color_two:"#303030"
    style: ButtonStyle
    {  background: Rectangle {
        implicitWidth: 100
        implicitHeight: 25
        border.width: control.activeFocus ? 2 : 1
        border.color: "black"
        radius: 1
        color: bg_sell
    }
}
visible: false
anchors.bottom: parent.bottom
anchors.right:  parent.right
width: parent.width/2-5
}
function stringExecut( _str,_spl)
{
    var a = []
    var res =""
    a = _str.split(_spl)
    for(var i=0;i<a.length;i++)
    {
        res += " ["
        res += a[i].substr(0,a[i].length-4);//chop(4)
        res += "] ["
        res += a[i].substr(a[i].length-4,2);//chop(4)
        res += "] ["
        res += a[i].substr(a[i].length-2,a[i].length);//chop(2)
        res += "]"
        res +="*"
    }


    return res
}
}

